package com.example.springbott.wx_controller;

import com.example.springbott.bean.BaseRespVo;
import com.example.springbott.bean.MarketUser;
import com.example.springbott.bean.zeng.AddordeleteBo;
import com.example.springbott.bean.zeng.CollectListVo;
import com.example.springbott.util.Count;
import com.example.springbott.wx_service.WxCollectService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import javax.servlet.http.HttpServletResponse;


/**
 * @author: zeng
 * @Description: 商品收藏模块
 * @date: 13:42 2022/11/22
 */


@RestController
@RequestMapping("wx/collect")
public class WXCollectController {
    @Autowired
    WxCollectService wxCollectService;

    @RequestMapping("list")
    public BaseRespVo list(Byte type, Integer page, Integer limit) {
        // Subject subject = SecurityUtils.getSubject();
        // MarketUser marketUser = (MarketUser) subject.getPrincipals().getPrimaryPrincipal();
        MarketUser marketUser = (MarketUser) SecurityUtils.getSubject().getPrincipal();
        if (marketUser == null) {
            return BaseRespVo.fail("需要重新登陆", Count.PLEASELOGIN);
        }
        // MarketUser marketUser = new MarketUser();
        CollectListVo collectListVo = wxCollectService.list(marketUser, type, page, limit);
        return BaseRespVo.ok(collectListVo);

    }

    @RequestMapping("addordelete")
    public BaseRespVo addordelete(@RequestBody AddordeleteBo addordeleteBo) {
        // Subject subject = SecurityUtils.getSubject();
        // MarketUser marketUser = (MarketUser) subject.getPrincipals().getPrimaryPrincipal();
        // MarketUser marketUser = new MarketUser();
        MarketUser marketUser = (MarketUser) SecurityUtils.getSubject().getPrincipal();
        if (marketUser == null) {
            return BaseRespVo.fail("需要重新登陆", Count.PLEASELOGIN);
        }
        Byte type = addordeleteBo.getType();
        Integer valueId = addordeleteBo.getValueId();
        wxCollectService.addordelete(marketUser, type, valueId);
        return BaseRespVo.ok();
    }

}
